import { defineStore } from "pinia";

import {getax,postax} from '@/common/request/index'

export const useSearchStore = defineStore('Search', {
    state: () => {
        return {
            tag: [],
            option: {
                pageNo: "0",
                pageSize:"30",
                animeTitleOrOtherTitle: '',
                animeType: "",
                hot: "",
                isAnimeOrCartoon: "",
                isOver: "",
                year: '',
                tag: "",
                r18:0
            },
            data: [],
            isFliterActive:true
        }
    },
    actions: {
        async getTag() {
            const {data:res} = await getax('api/tag/query')
            this.tag = res.data
        },
        QueryAsk(classifyid,id,tagName) {
            switch(classifyid){
                // 地区
                case 0: this.option.isAnimeOrCartoon = id === 0 ? '' : id - 1; break;
                case 1: this.option.animeType = id == 1 ? 0 : (id === 0 ? null : id); break;
                case 2: this.option.hot = id == 0 ? '' : 0; break;
                case 3: this.option.tag = id == 0 ? '' : id ; break;
                case 4: this.option.year = tagName - 1 ? tagName : ''; break;
            }
            this.getSearchData()
        },
        async getSearchData() {
                const {data:res} = await postax('api/anime/MultiConditionQuery',this.option)
                this.data = res.data || []
        }
    }
})